import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class HotGoodsArea extends StatelessWidget {
  final Map hotGoodsData;
  const HotGoodsArea({ Key key, this.hotGoodsData }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20.0)),
      child: Column(
        children: <Widget>[
          HotTitle(hotTitle: hotGoodsData['title'], iconLink: hotGoodsData['iconLink'],),
          HotGoodsList(goodsList: hotGoodsData['list'])
        ]
      ),
    );
  }
}

class HotTitle extends StatelessWidget {
  final String iconLink;
  final String hotTitle;
  const HotTitle({ Key key, this.hotTitle, this.iconLink }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(16.0)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Container(
            width: ScreenUtil().setWidth(32.0),
            height: ScreenUtil().setWidth(32.0),
            margin: EdgeInsets.only(right: 6.0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(ScreenUtil().setWidth(16.0)),
              image: DecorationImage(
                image: AssetImage(this.iconLink)
              )
            ),
          ),
          Text(this.hotTitle)
        ],
      ),
    );
  }
}

class HotGoodsList extends StatelessWidget {
  final List goodsList;
  const HotGoodsList({ Key key, this.goodsList }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final List<Widget> _goodsList = goodsList.map((item) {
      return Container(
        width: ScreenUtil().setWidth(345.0),
        margin: EdgeInsets.only(bottom: 10.0),
        child: InkWell(
          child: Column(
            children: <Widget>[
              Image.asset(item['imgUrl']),
              Text(item['title'], style: TextStyle(
                color: Colors.pink,
              ), maxLines: 1, overflow: TextOverflow.ellipsis,),
              Row(
                children: <Widget>[
                  Text('￥' + item['minPrice']),
                  Expanded(
                    child: Text('￥' + item['originPrice'], style: TextStyle(
                        decoration: TextDecoration.lineThrough,
                        color: Colors.black45
                      ),
                      textAlign: TextAlign.right,
                    )
                  )
                ],
              )
            ],
          ),
        ),
      );

    }).toList();

    return Wrap(
      spacing: ScreenUtil().setWidth(20.0),
      children: _goodsList,
    );
  }
}